package psd.core;

import java.util.Hashtable;

import org.eclipse.jdt.core.ICompilationUnit;


public class CompilationUnitManager {
	private static ICompilationUnit _currentCompilationUnit;
	private static CompilationUnitManager instance;
	private static Hashtable<Object, Object> compilationUnits;
	

	public static CompilationUnitManager Instance() {
		if (instance == null)
			instance = new CompilationUnitManager();
		return instance;
	}
	
	private CompilationUnitManager() {
		compilationUnits = new Hashtable<Object, Object>();
	}
	
	public Object get_CompilationUnit(Object key)
	{
		return compilationUnits.get(key);
	}
	
	private void add_CompilationUnit(Object key, Object compilationUnit)
	{
		if (!compilationUnits.contains(key))
			compilationUnits.put(key, compilationUnit);
	}

	public ICompilationUnit get_currentCompilationUnit() {
		return _currentCompilationUnit;
	}

	public void set_currentCompilationUnit(
			ICompilationUnit currentCompilationUnit) {
		_currentCompilationUnit = currentCompilationUnit;
		String compilationUnitPath = new StringBuilder("'").append(currentCompilationUnit.getPath().makeAbsolute().toString()).append("'").toString(); 
		add_CompilationUnit(compilationUnitPath, currentCompilationUnit);
	}
}
